package com.tuling.proxy;

import java.lang.reflect.Proxy;

public class ProxyFactory {
    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object newProxy(){

        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), (proxy, method, args) -> {
            System.out.println("增强前");
            Object result = method.invoke(this.target, args);
            System.out.println("增强后");
            return result;
        });
    }
}
